home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / JFC.bin / PopupButton.java < prev    next >
Text File  |  1998-06-30  |  2KB  |  81 lines

  1. /*
  2.  * @(#)PopupButton.java    1.2 97/08/26
  3.  * 
  4.  * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  */
  20.  
  21. package com.sun.java.swing;
  22.  
  23. import java.awt.*;
  24. import java.awt.event.*;
  25. import java.io.*;
  26.  
  27.  
  28. /** A button with an attached menu that sends a message to an Adjustable
  29.  * when a value is picked.  Generally connected to a Spinner.
  30.  * @author James Gosling
  31.  * @author Brian Gerhold
  32.  */
  33. public class PopupButton extends Component {
  34.   private Dimension d;
  35.   private JPopupMenu popup;
  36.   public PopupButton(JPopupMenu popup) 
  37.   {
  38.     this.popup = popup;
  39.     enableEvents(AWTEvent.MOUSE_MOTION_EVENT_MASK
  40.          |AWTEvent.MOUSE_EVENT_MASK);
  41.   }
  42.   public Dimension getMinimumSize() {
  43.     if (d == null)
  44.       {
  45.     d = new Dimension(14,8);
  46.       }
  47.     return d;
  48.   }
  49.   
  50.   protected void processMouseEvent(MouseEvent e){
  51.     if (e.getID()==e.MOUSE_PRESSED) 
  52.       {
  53.     popup.show(this,e.getX(),e.getY());
  54.       }
  55.     
  56.   }
  57.   protected void processMouseMotionEvent(MouseEvent e)
  58.   {}
  59.  
  60.   public Dimension getPreferredSize() 
  61.   {
  62.     return getMinimumSize();
  63.   }
  64.   private int xp[]=new int[4];
  65.   private int yp[]=new int[4];
  66.   public void paint(Graphics g) {
  67.     g.setColor(Color.black);
  68.     Dimension d = getSize();
  69.     int h = d.height;
  70.     int w = d.width-6;
  71.     xp[0] = 0; yp[0] = 0;
  72.     xp[1] = w-1; yp[1] = 0;
  73.     xp[2] = w>>1; yp[2] = h-1;
  74.     g.fillPolygon(xp,yp,3);
  75.   }
  76.   public void update(Graphics g) {
  77.     paint(g);
  78.   }
  79.   
  80. }
  81.